package sub

import (
	"fmt"
	"quipus/cmd/qpc/sub"
	v1pb "quipus/proto/gen/api/v1"

	"github.com/spf13/cobra"
)

var (
	provider string
	model    string
)

func init() {
	// sub.RegisterCommonFlags(tenantCmd)

	specCmd.PersistentFlags().StringVarP(&provider, "provider", "p", "", "provider name")
	specCmd.PersistentFlags().StringVarP(&model, "model", "m", "", "model name")
	providerCmd.AddCommand(specCmd)
}

var specCmd = &cobra.Command{
	Use:   "spec",
	Short: "Run spec to show provider specs",
	RunE: func(cmd *cobra.Command, args []string) error {
		qconn, e := sub.NewGrpcConnect(sub.QpConfig.QPAddress)
		if e != nil {
			return e
		}

		qclient := v1pb.NewLLMServiceClient(qconn)
		ctxWithToken := sub.NewCtxWithToken(sub.QpConfig.Token)
		in := &v1pb.ListLLMProviderSpecRequest{Provider: provider, Model: model}
		rsp, err := qclient.ListLLMProviderSpecs(ctxWithToken, in)
		if err != nil {
			return err
		}

		fmt.Println("URN               NAME           API           URL         TENANT       AUTH")
		if rsp != nil {
			for _, v := range rsp.Providers {
				fmt.Printf(v.String())
			}
		}
		// fmt.Print(rsp)
		return nil
	},
}
